package bridge

import (
	"fmt"
	"time"
)

type DataTypes string
const DATA_TYPE_INT = "int"
const DATA_TYPE_FLOAT = "float"
const DATA_TYPE_STRING = "string"
const DATA_TYPE_BOOL = "bool"
const DATA_TYPE_DATETIME = "datetime"

type DataField struct {
	Name string
	DataType DataTypes

	IntValue int
	FloatValue float64
	StringValue string
	BoolValue bool
	DateTimeValue *time.Time
}


func NewMockDataField(name string, dataType DataTypes) *DataField {
	it := &DataField {
		Name: name,
		DataType: dataType,

		IntValue: 0,
		FloatValue: 0,
		StringValue: "",
		BoolValue: false,
		DateTimeValue: nil,
	}

	switch dataType {
	case DATA_TYPE_INT:
		it.IntValue = 1
		break

	case DATA_TYPE_FLOAT:
		it.FloatValue = 1.1
		break

	case DATA_TYPE_STRING:
		it.StringValue = "hello"
		break

	case DATA_TYPE_DATETIME:
		t := time.Now()
		it.DateTimeValue = &t
		break

	case DATA_TYPE_BOOL:
		it.BoolValue = false
		break
	}

	return it
}

func (me *DataField) ValueString() string {
	switch me.DataType {
	case DATA_TYPE_INT:
		return fmt.Sprintf("%v", me.IntValue)

	case DATA_TYPE_FLOAT:
		return fmt.Sprintf("%v", me.FloatValue)

	case DATA_TYPE_STRING:
		return fmt.Sprintf("\"%s\"", me.StringValue)

	case DATA_TYPE_DATETIME:
		return fmt.Sprintf("\"%s\"", me.DateTimeValue.Format("2006-01-02T15:04:05"))

	case DATA_TYPE_BOOL:
		return fmt.Sprintf("%v", me.BoolValue)
	}

	return ""
}